package com.zxx.dis.factory;

import com.zxx.dis.core.DistributedLockFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

@Component
public class DistributedLockFactoryCreator {
    private final Map<String, DistributedLockFactory> factories;

    @Autowired
    public DistributedLockFactoryCreator(RedisDistributedLockFactory redisFactory) {
        factories = new ConcurrentHashMap<>();
        factories.put("redis", redisFactory);
    }

    public DistributedLockFactory getFactory(String type) {
        DistributedLockFactory factory = factories.get(type.toLowerCase());
        if (factory == null) {
            throw new IllegalArgumentException("Unsupported lock type: " + type);
        }
        return factory;
    }
}
